package com.dxt.filters;

import com.dxt.pojo.User;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

/**
 * ClassName: LoginFilter
 * Package: com.dxt.filters
 * Description:
 *
 * @Author 段鑫涛
 * @Create 2025/3/31 18:21
 * @Version 1.0
 */
@WebFilter(value = {"*.jsp","/delivery/*","/user/*"})
public class LoginFilter extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        if(user == null){
            response.sendRedirect("/login.html");
        }else{
            chain.doFilter(request, response);
        }
    }
}
